package com.eaoa.uc.account.bo;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.eaoa.base.EABaseBusinessObject;
import com.eaoa.dao.pub.PubAccountDAO;
import com.eaoa.vo.pub.PubAccount;
import com.eaoa.vo.pub.PubRole;

public class AccountRoleSettingBO extends EABaseBusinessObject {
	private static PubAccountDAO accountDAO = new PubAccountDAO(); 
	private Long accountno;
	private List rolenos;
	Long roleno;

	public AccountRoleSettingBO(Long accountno, List rolenos) {
		super();
		this.accountno = accountno;
		this.rolenos = rolenos;
	}
	
	public AccountRoleSettingBO(Long accountno, Long roleno) {
		super();
		this.accountno = accountno;
		this.roleno = roleno;
	}

	protected void performBusinessLogic() {
		if(rolenos==null && roleno!=null){
			rolenos = new ArrayList();
			rolenos.add(roleno);
		}
		
		Set roles = new HashSet();
		
		for(int i=0; i<rolenos.size(); i++){
			PubRole role = new PubRole();
			role.setRoleno((Long)rolenos.get(i));
			roles.add(role);
		}
		
		PubAccount account= (PubAccount)accountDAO.loadAndLock(accountno);
		account.setPubRoles(roles);
		accountDAO.update(account);
	}
}